package com.cz.token;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.Map;

public class LoginService {

    public String getProdToken() {
        String token = null;
        String url = "http://ams.prod.ant2world.com/api/at-ams-api/security/login";
        Map<String, Object> requestMap = new HashMap<>();
        requestMap.put("loginType", 1);
        requestMap.put("username", "chenzhen");
        requestMap.put("password", "chenzhen123");
        requestMap.put("clientId", "admin-app");
        HttpResponse response = HttpRequest.post(url)
                .body(JSONUtil.toJsonStr(requestMap))
                .execute();

        if (response.isOk()) {
            String responseBody = response.body();
            JSONObject jsonObject = JSONUtil.parseObj(responseBody);
            token = jsonObject.getJSONObject("data").getJSONObject("data").getStr("token");
        }
        return token;
    }

    public String getUat3Token() {
        String token = null;
        String url = "http://ams.uat3.ant2world.com/api/at-ams-api/security/login";
        Map<String, Object> requestMap = new HashMap<>();
        requestMap.put("loginType", 1);
        requestMap.put("username", "admin");
        requestMap.put("password", "admin");
        requestMap.put("clientId", "admin-app");
        HttpResponse response = HttpRequest.post(url)
                .body(JSONUtil.toJsonStr(requestMap))
                .execute();

        if (response.isOk()) {
            String responseBody = response.body();
            JSONObject jsonObject = JSONUtil.parseObj(responseBody);
            token = jsonObject.getJSONObject("data").getJSONObject("data").getStr("token");
        }
        return token;
    }

    public static void main(String[] args) {
        LoginService loginService = new LoginService();
        String token =loginService.getProdToken();
        System.out.println(token);
    }
}
